package samoloty.view;

import Utils.ScreensOrder;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.KeyStroke;
import javax.swing.border.Border;
import javax.swing.event.MouseInputListener;

/**
 *
 * @author borysfan
 */
public class MyNewButton extends MyButton{

    private MyNewButton instance;

    public MyNewButton(String name) {
        super(name);
        initButton(90, 40);
        instance = this;
    }

    public MyNewButton(String line, String line2) {
        super(line,line2);
        initButton(90, 40);
        instance = this;
    }


    private void initActions(){
        addFocusListener(new ButtonFocus());
        addMouseMotionListener(new MyMouseEvent());
    }



    private void initButton(int width, int height) {
        this.setBounds(0, 0, width, height);
        this.setMinimumSize(new Dimension(width, height));
        this.setMaximumSize(new Dimension(width, height));
        this.setPreferredSize(new Dimension(width, height));
        this.initActions();
        this.setOpaque(true);
        this.setFont(new Font("Tahoma", 0, 16));
        this.setFocusable(true);
        this.registerKeyboardAction(this.getActionForKeyStroke(
                KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)),
                KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false),
                JComponent.WHEN_FOCUSED);

        this.registerKeyboardAction(this.getActionForKeyStroke(
                KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)),
                KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true),
                JComponent.WHEN_FOCUSED);
        setAlignmentX(Component.CENTER_ALIGNMENT);
    }



    private class ButtonFocus implements FocusListener {

        public void focusGained(FocusEvent e) {
            instance.setBorder(BorderFactory.createLineBorder(Color.WHITE, 3));

        }

        public void focusLost(FocusEvent e) {
            instance.setBorder(null);
        }
    }

    private class MyMouseEvent implements MouseMotionListener{



        public void mouseEntered(MouseEvent e) {
            instance.setBorder(BorderFactory.createLineBorder(Color.WHITE, 3));
        }

        public void mouseExited(MouseEvent e) {
            instance.setBorder(null);
        }

        public void mouseDragged(MouseEvent e) {
        }

        public void mouseMoved(MouseEvent e) {
        }

    }

}
